<!-- Dom模板 -->
<template>
  <div class="login">
    <!-- Dom内容 -->
    <div class="item">
      <h2>后台管理系统</h2>
      <div class="con">
        <p>邮箱：<input type="text" v-model="user" /></p>
        <p>密码：<input type="password" v-model="pass" /></p>
        <p class="mm" v-if="flag">{{ res }}</p>
      </div>
      <div class="btn">
        <button @click="click">登录</button>
        <button @click="zc">注册</button>
      </div>
    </div>
  </div>
</template>

<script>
// import a from './a'; // 引入组件
export default {
  name: "",
  data() {
    return {
      msg: "测试",
      user: "",
      pass: "",
      flag: false,
      res: "",
    };
  },
  // 生命周期 - 创建完成（访问当前this实例）
  created() {},
  // 生命周期 - 挂载完成（访问DOM元素）
  mounted() {
    console.log(this.$router);
    this.getNavList();
  },
  // Vue方法定义
  methods: {
    getNavList() {
      this.$store.dispatch("login/Set");
    },
    click() {
      this.$store
        .dispatch("login/getNavList", {
          user: this.user,
          pass: this.pass,
        })
        .then((res) => {
          console.log(res);
          this.$router.push("/Administrator");
        })
        .catch((err) => {
          this.flag = true;
          this.res = err;
        });
    },
    zc() {
      var rge = /^\w+@\w+\.(com|cn|net)$/;
      var mi = /^[a-z0-9]{6,20}$/i;
      if (!rge.test(this.user)) {
        this.flag = true;
        this.res = "邮箱格式错误";
      } else if (!mi.test(this.pass)) {
        this.flag = true;
        this.res = "密码为6~10位字母、数字组合";
      } else {
        this.$store.commit("login/Zc", {
          user: this.user,
          pass: this.pass,
        });
      }
    },
  },
};
</script>

<style scoped>
/* @import url(''); 引入css类 */
* {
  padding: 0;
  margin: 0;
}
.login {
  width: 100%;
  height: 100%;
  background-color: #4a5259;
  position: fixed;
  top: 0;
  left: 0;
}
h2 {
  margin-top: 70px;
  text-align: center;
}
input {
  width: 200px;
  height: 30px;
  outline: none;
}
.item {
  width: 400px;
  background-color: white;
  height: 400px;
  position: fixed;
  left: 50%;
  top: 50%;
  margin-top: -200px;
  margin-left: -200px;
  border-radius: 20px;
}
.con {
  margin-top: 20px;
  position: relative;
}
.yx {
  position: absolute;
  top: 35px;
  left: 50px;
  color: red;
}
.mm {
  position: absolute;
  top: 100px;
  left: 50px;
  color: red;
}
.item p {
  margin-bottom: 30px;
  margin-left: 50px;
}
.btn {
  position: absolute;
  top: 65%;
  left: 23%;
}
button:nth-child(1) {
  width: 100px;
  height: 30px;
  background-color: blue;
  color: white;
  border-radius: 20px;
  border-color: blue;
}
button:nth-child(2) {
  width: 100px;
  height: 30px;
  border-radius: 20px;
  margin-left: 10px;
}
</style>